import NProgress from "nprogress"
import "@/styles/nprogress.css"
import router from "@/router/index.js";
import {getToken} from "@/utils/token.js"

NProgress.configure({showSpinner: false});

router.beforeEach((to, from, next) => {
    NProgress.start();

    if (getToken()) {
        if (to.path === "/login") {
            next({path:"/"})
            return
        }
    }else{
        if (to.path !== "/login") {
            next({path:"/login"})
            return
        }
    }

    console.log(to, from)
    next()
})

router.afterEach((to, from) => {
    NProgress.done();
})